package com.dhcc.sds.busi.controller;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.service.ICdcHospitalService;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.sds.base.service.ISdsCommonService;
import com.dhcc.sds.base.service.ISdsQcentityService;
import com.dhcc.sds.busi.dto.AnalysisExclusionDto;
import com.dhcc.sds.busi.service.IAnalysisSdsExclusionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 单病种排除情况统计
 *
 * @author zhangdc
 * @ClassName: AnalysisSdsExclusionController
 * @Description: TODO
 * @date 2023-06-20 10:09:15
 */
@Controller
@RequestMapping("${sys.backendPath}/analysis/exclusion")
public class AnalysisSdsExclusionController {

    private String PREFIX = "/backend/sds/exclusion/";

    @Autowired
    private ICdcHospitalService cdcHospitalService;
    @Autowired
    private ISdsCommonService sdsCommonService;
    @Autowired
    private ISdsQcentityService sdsQcentityService;
    @Autowired
    private IAnalysisSdsExclusionService sdsExclusionService;


    /**
     * @Description: 跳转到排除情况统计页面
     * @Title:
     * @author: zhangdc
     * @date:2023-06-20 10:09:15
     */
    @RequestMapping("")
    public String index(Model model){
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("entityMap",entityMap);
        model.addAttribute("hospitalId",sdsCommonService.getHospIdBySysUser());
        return PREFIX + "exclusion.html";
    }

    @RequestMapping("selectSdsExclusionTable")
    @ResponseBody
    /*public Object selectSdsExclusionTable(@RequestParam Map<String, Object> params) {
        // 查询登录用户关联科室
        //List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        //params.put("userLinkDepts", deptIds);
        return sdsExclusionService.selectSdsExclusionTable(params);
    }*/
    public Object caseList(@RequestParam Map<String, Object> params) {
        // 查询登录用户关联科室
        List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        params.put("userLinkDepts", deptIds);
        Page<AnalysisExclusionDto> page = new PageFactory<AnalysisExclusionDto>().defaultPage();
        List<AnalysisExclusionDto> result = sdsExclusionService.pageExclusionTable(page, params);
        page.setRecords((List<AnalysisExclusionDto>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

}
